clear all
set more off, permanently

global replica_dir="<add path to your working directory>"
global data_dir="$replica_dir/data"
global output_dir="$replica_dir/output"

global simce_data_dir="<add path to your SIMCE data directory>"
*------------------------------------------------------------------------------*

* SIMCE 2015

*------------------------------------------------------------------------------*

**# Student scores

/*
	Note:
	
	idalumno: 	unique identifier for "mrun-letra_curso-cod_curso" record  
				important when linking it to teacher survey piece, use together with letra_curso-cod_curso
	
	mrun: unique student identifier to link data across years
	
------------------------------------------------------------------------------*/
 
cd "$data_dir" 
 
set more off
use "$simce_data_dir/8B/simce8b2015/Archivos DTA (Stata)/simce8b2015_alu_publica_final.dta", clear

keep if noptje_lect8b_alu==0 | noptje_mate8b_alu==0 | noptje_nat8b_alu==0 // con puntaje

rename  (ptje_lect8b_alu 	ptje_mate8b_alu 	ptje_nat8b_alu) /// 
		(lect_post			mate_post			nat_post)

duplicates report mrun
duplicates examples mrun
duplicates tag mrun, g(ndupobs)
//browse if ndupobs>0
unique mrun

keep if ndupobs==0
		
keep mrun rbd lect_post mate_post nat_post  

save "$data_dir/simce_b8_2015.dta", replace



*------------------------------------------------------------------------------*

**#  School survey

*------------------------------------------------------------------------------*

use "$simce_data_dir/8B/simce8b2015/Archivos DTA (Stata)/simce8b2015_rbd_publica_final.dta", clear

egen sch_stno_post = rowmax(nalu_lect8b_rbd nalu_mate8b_rbd nalu_nat8b_rbd)

rename  (cod_depe1 		cod_grupo 		cod_reg_rbd) /// 
		(sch_depe1_post	sch_gse_post	cod_reg_rbd_post)

keep  rbd sch_stno_post sch_depe1_post sch_gse_post cod_reg_rbd_post

merge 1:m rbd using "$data_dir/simce_b8_2015.dta"
//browse if _merge==1
keep if _merge==3
drop _merge

rename rbd rbd_post
sort mrun

save "$data_dir/simce_b8_2015.dta", replace


*------------------------------------------------------------------------------*



 
